<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ include file="/WEB-INF/views/common.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script type="text/javascript">
	$(function(){
		var uploadForm = $("#uploadForm");
		var downLoadForm = $("#downLoadForm");
		var studentDatagrid = $("#studentDatagrid");
		var cmdObject = {
				import : function() {
					uploadForm.form('submit',{
						url : "/student/upload",
						//后台加验证，防止被脚本导入错误文件
						success : function(data) {
							var data = JSON.parse(data);
							if(data.code == 0) {
								$.messager.alert('提示', data.msg, 'info');
								var file = $("#file") 
								file.after(file.clone().val("")); 
								file.remove();
								//重新刷新departmentDatagrid
								studentDatagrid.datagrid('reload');
							} else {
								$.messager.alert('提示', data.msg, 'error');
							}
						}
					})
				},
				downLoadForm : function() {
					downLoadForm.form('submit', {
						url : "/student/downLoad",
						success : function(data) {
							var data = JSON.parse(data);
							if(data.code == 0) {
								$.messager.alert('提示', data.msg, 'info');
							} else {
								$.messager.alert('提示', data.msg, 'error');
							}
						}
					})
				},
				deleteAll : function() {
					$.messager.confirm('提示', '确定要清空考生表？', function(r) {
						if (r) {
							$.get("/student/deleteAll", function(data) {
								if (data.code == 0) {
									//重新刷新Datagrid
									$.messager.alert('提示', data.msg, 'info');
									studentDatagrid.datagrid('reload');
								} else {
									$.messager.alert('提示', data.msg, 'error');
								}
							});
						}
					})
				}
				
			}
			$("a[data-cmd]").on('click', function() {
				var cmd = $(this).data("cmd");
				if (cmd && !$(this).hasClass('l-btn-disabled')) {
					cmdObject[cmd]();
				}
			});
	})
	function stateFormat(value, row, index) {　/* 标准格式，应使用枚举 */
		var result = '';
		if (value == 0) {
			result = '未 考';
		} else if (value == 1) {
			result = '<font color="blue">正在考试</font>';
		} else if(value == 2) {
			result = '通 过';
		} else {
			result = '<font color="red">未通过</font>';
		}
		return result;
	}

</script>
<body>
<table id="studentDatagrid" class="easyui-datagrid" toolbar="#studentTooBar"
		url="/student/list" pagination="true" fit="true" fitColumns="true"
		singleSelect="true" striped="true">
		<thead>
			<tr>
				<th field="idx" align="center" width="40">序号</th>
				<th field="grade" align="center" width="40">年级</th>
				<th field="department" align="center" width="60">学院</th>
				<th field="major" align="center" width="100">专业</th>
				<th field="name" align="center" width="50">姓名</th>
				<th field="studentNo" align="center" width="60">学号</th>
				<th field="schoolNo" align="center" width="60">党校号</th>
				<th field="examState" align="center" width="50" formatter="stateFormat">初考状态</th>
				<th field="examScore" align="center" width="50">初考成绩</th>
				<th field="makeUpState" align="center" width="50" formatter="stateFormat">补考状态</th>
				<th field="makeUpScore" align="center" width="50">补考成绩</th>
			</tr>
		</thead>
	</table>
	<div id="studentTooBar">
		<form id="uploadForm" enctype="multipart/form-data" method="post">
			<input type="file" class="easyui-filebox" id="file" 
				name="file" style="width:160px;">
			<a id="import"
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" data-cmd="import">导入</a>
			<a id="delete"
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" data-cmd="deleteAll">清空考生</a>
		</form>
		<form id="downLoadForm" enctype="multipart/form-data" method="post">			
			<a id="downLoad"
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" data-cmd="downLoadForm">下载学生表</a>
		</form>
	</div>
		
	
</body>
</html>